<?php

namespace app\api\server\music;

use app\api\model\music\MusicSkewerApiModel;
use app\api\model\music\MusicSkewerTypeApiModel;
use app\api\model\music\MusicWelfareApiModel;
use app\api\ServerBase;
use app\logic\single\GoodsSingle;
use think\Request;

class MusicWelfareServer extends ServerBase
{
    /**
     * @var MusicWelfareApiModel
     */
    private $model;
    /**
     * @var array|mixed
     */
    private $param;

    function __construct(Request $request)
    {
        $this->request=$request;
        $this->param=$request->param();
        $this->model=new MusicWelfareApiModel();
    }

    function getList(){
        [$page,$limit] = $this->getPage($this->param);
        $field= 'id,goods_id,type,price,start_time,end_time';
        $this->param['status'] = 1;
        [$list,$count] = $this->model->getApiList($this->param,[],$field,$page,$limit);
        $result['data']=$list;
        $result['count']=$count;
        $this->getMessageCode('adminMessage.success.select',2);
        return $result;
    }

    function getDetail(){
        $id =  $this->request->param('id');
        $info = $this->model->details($id,'id,goods_id,type,price,start_time,end_time');
        if(empty($info)){
            $this->getMessageCode('code_common.not_find',1);
            return false;
        }
        $info['is_have'] = GoodsSingle::getInstance()->isHave($info['goods_id'],$info['type'],$this->request->user_id);
        $this->getMessageCode('adminMessage.success.select',2);
        return $info;
    }
}